home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / editor / snmp_0_1.zip / snmp-0.1 / aka / snmp / TypeTimeTick.java < prev   
Text File  |  1997-06-09  |  2KB  |  103 lines

  1. /*
  2. Snmp Library
  3. Copyright (C) 1997 Alex Kowalenko Associates Pty Ltd. All rights reserved.
  4.  
  5. This software maybe be free distributed, any any form, without fee, 
  6. but may not be modified in any way without express permission of 
  7. the directors of Alex Kowalenko Associates Pty Ltd. 
  8.  
  9. Alex Kowalenko Associates Pty Ltd makes no representations or
  10. warranties about the suitabililty of the software, not even the
  11. implied warranty of merchantability or fitness for any particular
  12. purpose.    
  13. */
  14.  
  15. package aka.snmp;
  16.  
  17. /**
  18.  * SNMP KTIMETICK Type
  19.  * @see Type
  20.  * @version     $Id: TypeTimeTick.java,v 1.3 1997/05/18 08:11:54 alex Exp $
  21.  * @author      Alex Kowalenko
  22.  */
  23.  
  24. public class TypeTimeTick extends TypeInt {
  25.  
  26.     static byte asnValue = ASN.TIMETICKS;
  27.     static String name = "TimeTicks";
  28.  
  29. /**
  30.  * Constructor
  31.  */    
  32.  
  33.     TypeTimeTick() {
  34.     super();
  35.     }
  36.  
  37. /**
  38.  * Constructor from integer
  39.  */
  40.  
  41.     TypeTimeTick(int value) {
  42.     super(value);
  43.     }
  44.  
  45. /**
  46.  * Constructor from ByteBuffer
  47.  */
  48.  
  49.     TypeTimeTick(ByteBuffer buffer) {
  50.     super(buffer);
  51.     };
  52.  
  53. /**
  54.  * returns name of Type
  55.  */
  56.  
  57.     String typeName() {
  58.     return name;
  59.     };
  60.   
  61. /**
  62.  * SNMP protocol conversion.  Convert the variable to a sequence of 
  63.  * bytes, according to SNMP Protocol rules.
  64.  */
  65.  
  66.   public ByteBuffer BERSerialize() {
  67.       ByteBuffer buffer = super.BERSerialize();
  68.       if(buffer.size() > 0)
  69.       buffer.setByteAt(0, asnValue);
  70.       return buffer;
  71.   };
  72.  
  73. /**
  74.  * Return a String representation of the type
  75.  */
  76.  
  77.   public String toString() {
  78.       int d, h, m, s, ds;
  79.     
  80.       StringBuffer result = new StringBuffer(super.toString());
  81.       result.append(" (");
  82.      
  83.       ds = value();
  84.       s = ds / 100; ds = ds % 100;
  85.       m = s / 60;    s = s  % 60;
  86.       h = m / 60;    m = m  % 60;
  87.       d = h / 24;    h = h  % 24;
  88.     
  89.       if( d > 0)
  90.       result.append( d + " days, ");
  91.       if( d > 0 || h > 0)
  92.       result.append( h + " hours, ");
  93.       if(d > 0 || h > 0 || m > 0)
  94.       result.append( m + " minutes ");
  95.       result.append(s);
  96.       if(ds > 0)
  97.       result.append("." + ds);
  98.       result.append(" seconds)");
  99.       return result.toString();
  100.   }
  101.  
  102. };
  103.